<%@page import="com.group.dataroom.DataBean"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<jsp:useBean id="dataMgr" class="com.group.dataroom.DataMgr"/>
<%
	request.setCharacterEncoding("utf-8");

	int start, end, pageSu, spage = 1;
	int plist;
	
	if(request.getParameter("plist_set")!=null){
		plist = Integer.parseInt(request.getParameter("plist_set"));
		dataMgr.setPlist(plist);
	}	
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>자료실 - 메인</title>
<script type="text/javascript">
	function check(){
		//alert("aa");
		if(frm.team.value===""){
			alert("검색어를 입력하시오");
			frm.team.focus();
			return;
		}		
		frm.submit();
	}
</script>
</head>
<body bgcolor="beige">
	<jsp:include page="../common/top.jsp" />
	<br>
		<br>
		<h3>&nbsp;&nbsp;
			<b><img src="../img/file.jpg" /> 자료실 - 메인</b>
		</h3><hr>
		<table>
			<tr>
				<td align="left">
					<b><img src="../img/point.jpg"/>inserted File All View</b> 
				</td>
			</tr>
		</table>
		
		<table align="right">
			<tr>
				<td>
				<form action="../dataroom/file_main.jsp" method="post"name="frm">
					<select name="stype">
						<option value="FileName" selected="selected">Title</option>
						<option value="User_Name">UserName</option>
						<option value="Cont" >Content</option>					
					</select>
					<input type="text" name="team">
					<input type="button" value="Search" onclick="check()">
				</form>
				</td>
			</tr>
		</table><br>
		<table>
			<tr>
				<td>
					<input type="radio"  name="radio"> File name
				</td>
				<td>
					<input type="radio"  name="radio">Last update</td>
			</tr>
			<tr>
				<td align="left">
					<input type="radio" id="UserName" name="radio">UserName
				</td>
				<td>
					<input type="radio" id="Download" name="radio">Download count
				</td>
			</tr>
		</table>
		
		<table align="right">
			<tr>
				<td>
				<form action="../dataroom/file_main.jsp" method="post" name="plist_frm">
					<select name="plist_set">
						<option value="5" selected="selected">5줄보기</option>
						<option value="10">10줄보기</option>
						<option value="15" >15줄보기</option>					
					</select>
					<input type="submit" value="보기">
				</form>
				</td>
			</tr>
		</table>
		<br><br><br>
		<table width="100%" border="1">
			<tr bgcolor="ace7ff">
				<th width="30">No</th>
				<th width="50">User Name</th>
				<th width="50">Title</th>
				<th width="50">File DownLoad</th>
				<th width="150">Content</th>
				<th width="30">Date</th>
			</tr>
			<%
				request.setCharacterEncoding("utf-8");
				try{
					spage = Integer.parseInt(request.getParameter("page"));
				}catch(Exception e){
					spage =1;
				}
				if(spage <= 0) spage =1;
				
				String type = request.getParameter("stype");// 검색에서 넘어오는 값(작성자, 글제목, 글내용)
				String word = request.getParameter("team"); // 검색창의 내용
				
				//페이지 단위 작업
				dataMgr.totalList(word, type); //레코드 전체 개수 구함
				pageSu = dataMgr.getPagesu(); //총 페이지 수
				//out.print("총페이지 수 : "+pageSu);
				
				ArrayList<DataBean> list = dataMgr.getDataBean(word,type,spage);   
				
				for(int i=0; i<list.size(); i++){
					DataBean bean=list.get(i);
			%>
			<tr align="center">
				<td><%=bean.getNo() %></td>
				<td><%=bean.getUser_name() %></td>
				<td align="left" style="padding-left: 20px">
					<a href="file_content.jsp?no=<%=bean.getNo() %>&page=<%=spage%>" onfocus="blur()">
					<%=bean.getFilename() %></a>
				</td>
				<td align="left" style="padding-left: 20px"><%=bean.getFdata() %></td>
				<td align="left" style="padding-left: 20px"><%=bean.getCont() %></td>
				<td><%=bean.getWritedate() %></td> 
			</tr>
			<%
			}
			%>
		</table><br><br><br><br><br><br><br><br>
		<table align="right">
			<tr>
				<td align="right">
					<input type="button" value="File Upload" onClick="location.href='file_add.jsp'"/>
				</td>
			</tr>
		</table>
		<br><br><br><br>
			<table align="center">
				<tr>
				<td>
				<%
					for(int p=1; p <=pageSu;p++){
						if( p == spage){
							out.print("<b style='font-size:12pt; color:red'>["+ p+"]</b>");
						}else{
							out.print("<a href='file_main.jsp?page="+ p+"'>["+p+"]</a>");
						}
					}
				%>
				<br><br>
				</td>
			</table>
	</tr>
	</form>
</body>
</html>